var nums = [0, 1, 2, 2, 3, 0, 4, 2]
var val = 2;


var removeElement = function (nums, val) {
    var n = nums.length;
    if (n === 0) {
        return n;
    }
    var fast = 0, slow = 0;
    while (fast < n) {
        if (nums[fast] !== val) {
            nums[slow] = nums[fast];
            ++slow
        }
        ++fast
    }
    return slow;

};
console.log(removeElement(nums, val));
